﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace DMS.Base
{
    public class Helper
    {
        protected static int GetRecordCount(string sql, List<DbParameter> dbParams)
        {
            Database db = DBHelper.Instance;
            DbCommand command = db.GetSqlStringCommand(sql);
            if (dbParams != null && dbParams.Count > 0)
            {
                foreach (DbParameter param in dbParams)
                {
                    DbParameter p = command.CreateParameter();

                    p.Direction = param.Direction;
                    p.DbType = param.DbType;

                    p.ParameterName = param.ParameterName;
                    p.Value = param.Value;

                    command.Parameters.Add(p);

                }
            }

            return Convert.ToInt32(db.ExecuteScalar(command));
        }
    }
}
